import Vue from "vue";
import Router from "vue-router";
//vue中使用Router
Vue.use(Router);

const router = new Router({
  mode: "history", //将路由模式改为history(没有#)
  //routes对路由的配置
  routes: [
    {
      path: "/",
      component: () => import("@/components/layouts"),
      //用childrens配置子路由
      children: [
        {
          path: "", //
          component: () => import("@/views/auth/login"),
        },
      ],
    },
    {
      path: "/refresh",
      component: () => import("@/components/layouts"),
      //用childrens配置子路由
      children: [
        {
          path: "", //
          component: () => import("@/views/auth/refresh"),
        },
      ],
    },
  ],
});

import store from "@/store";
//用router.beforeEach进行对接口的拦截 /logout
router.beforeEach((to, from, next) => {
  //调用了此接口
  if (to.path === "/logout") {
    store.dispatch("UserLogout", to.query.redirectURL);
  } else {
    next();
  }
});

//默认导出
export default router;
